package com.enzoism.thread.a04countdownlatch;

import com.enzoism.thread.common.MyRunnable;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IntelliJ IDEA.
 * User: enzoism
 * Desc: 练习CountDownLatch使用
 * URL: https://www.jianshu.com/p/bb5105303d85
 * Date: 2020/8/6- 23:41
 */
public class A01_CountDownLatch {
    private final static int THREADCOUNT = 200;

    public static void main(String[] args) throws Exception {
        // 1、创建一个线程池，用来提交线程任务
        ExecutorService executorService = Executors.newCachedThreadPool();

        // 2、创建一个CountDownLatch,用来进行线程技术
        CountDownLatch countDownLatch = new CountDownLatch(THREADCOUNT);

        // 3、创建线程
        for (int i = 0; i < THREADCOUNT; i++) {
            final int threadNum = i;
            executorService.execute(new MyRunnable(threadNum));
        }
    }


}
